package client_conn

import "net"

var connToDeviceID = make(map[net.Conn]int, 0)
var deviceIDToConn = make(map[int]net.Conn, 0)

func Get(conn net.Conn) int {
	id, ok := connToDeviceID[conn]
	if !ok {
		return 0
	}
	return id
}

func GetConn(id int) net.Conn {
	conn, ok := deviceIDToConn[id]
	if !ok {
		return nil
	}
	return conn
}

func Set(conn net.Conn, id int) {
	connToDeviceID[conn] = id
	deviceIDToConn[id] = conn
}

func Remove(conn net.Conn) {
	id := Get(conn)
	delete(deviceIDToConn, id)
	delete(connToDeviceID, conn)
}
